package com.xingdata.jjxc.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xingdata.jjxc.R;
import com.xingdata.jjxc.enty.ComAddressEntity;

/**
 * 以前收藏adapter
 * 
 * @author ysc
 * 
 */
public class CommAddressAdp extends BaseAdapter {

	private Activity avt;
	private List<ComAddressEntity> comEnlist;

	public CommAddressAdp(Activity avt, List<ComAddressEntity> comEn) {
		super();
		this.avt = avt;
		this.comEnlist = comEn;
	}

	@Override
	public int getCount() {
		return comEnlist == null ? 0 : comEnlist.size();
	}

	@Override
	public ComAddressEntity getItem(int position) {
		return comEnlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(avt).inflate(R.layout.item_common_address, null);

			holder.item_common_compyname_tv = (TextView) convertView.findViewById(R.id.item_common_compyname_tv);
			holder.item_common_compyaddress_tv = (TextView) convertView.findViewById(R.id.item_common_compyaddress_tv);

			holder.item_comm_add_iv = (ImageView) convertView.findViewById(R.id.item_comm_add_iv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		ComAddressEntity com = getItem(position);
		holder.item_common_compyname_tv.setText(com.getNick_address());
		holder.item_common_compyaddress_tv.setText(com.getReal_address());

		if ("10".equals(com.getSite_id())) {
			holder.item_comm_add_iv.setBackgroundResource(R.drawable.home_jjxc);
			holder.item_common_compyaddress_tv.setText("点击去设置");
		} else if ("11".equals(com.getSite_id())) {
			holder.item_comm_add_iv.setBackgroundResource(R.drawable.gongsi_jjxc);
			holder.item_common_compyaddress_tv.setText("点击去设置");
		}

		holder.item_comm_add_iv.setBackgroundResource(R.drawable.my_addre_list);

		return convertView;
	}

	final class ViewHolder {
		public TextView item_common_compyname_tv, item_common_compyaddress_tv;

		public ImageView item_comm_add_iv;
	}

}
